//
//  YanTabBar.m
//  AddingMom
//
//  Created by zhaochengfeng on 16/6/20.
//  Copyright © 2016年 zhaochengfeng. All rights reserved.
//

#import "YanTabBar.h"
#import "AppDelegate.h"

@interface YanTabBar ()<UITabBarControllerDelegate>

@end

@implementation YanTabBar

- (void)viewDidLoad {
    [super viewDidLoad];
    self.delegate = self;
    [self createTabBar];
}

- (void)createTabBar{
    
    [[UIBarButtonItem appearance] setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
    [UINavigationBar appearance].barTintColor = HCMainTintColor;
    [[UINavigationBar appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:17],NSForegroundColorAttributeName : [UIColor whiteColor]}];
    NSArray *normalImage = @[@"Film_Normal",@"Discovery_Normal",@"Play_Normal",@"I_Normal"];
    NSArray *selectedImage = @[@"Film_Hover",@"Discovery_Hover",@"Play_Hover",@"I_Hover"];
    NSArray *controllerArr = @[@"CinemaController",@"FilmPlanController",@"TicketController",@"MineController"];
    NSArray *titleArr = @[@"影院",@"排片",@"网售",@"我的"];
    
    NSMutableArray *navArr = [[NSMutableArray alloc]init];
    for (int i = 0; i<normalImage.count; i++) {
        Class controllerClass = NSClassFromString(controllerArr[i]);
        UIViewController *vc = [[controllerClass alloc]init];
        UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:vc];
        nav.tabBarItem.image = [UIImage imageNamed:normalImage[i]];
        
        UIImage *image = [UIImage imageNamed:selectedImage[i]];
        image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        nav.tabBarItem.selectedImage = image;
        nav.tabBarItem.title = titleArr[i];
        [[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName :HCMainTintColor} forState:UIControlStateSelected];
        [navArr addObject:nav];
    }
    self.viewControllers = navArr;
}

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
    
//    NSInteger index = [tabBarController.viewControllers indexOfObject:viewController];
//    UINavigationController *nc = (UINavigationController *)viewController;
//    if (index == 4 && [NSUserDefaults standardUserDefaults].hasLogin == NO) {
//        nc.viewControllers = @[[[phoneLoginViewController alloc] init]];
//    }
    return YES;
}

//- (void)chageRootVc {
//    AppDelegate *myApp = (AppDelegate *)[UIApplication sharedApplication].delegate;
//    YanTabBar *myTab = (YanTabBar *)myApp.window.rootViewController;
//    
//    UINavigationController *nc = (UINavigationController *)[myTab.viewControllers lastObject];
//    if ([NSUserDefaults standardUserDefaults].hasLogin == NO) {
//        phoneLoginViewController *login = [[phoneLoginViewController alloc] init];
//        NSMutableArray *array = [NSMutableArray arrayWithArray:nc.viewControllers];
//        [array replaceObjectAtIndex:0 withObject:login];
//        [nc popToRootViewControllerAnimated:YES];
//    }
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
